package com.yk.framework.gui.core;

import java.util.HashMap;
import java.util.Iterator;

import com.yk.framework.gui.core.impl.CoreUI;

/**
 * @author lifetime
 * 
 */
public class UIFactory {

	public static CoreUI createUI(String uiClassName, HashMap<String, Object> ctx, String uiState) throws Exception {
		Class class1 = Class.forName(uiClassName);
		CoreUI ui = (CoreUI) class1.newInstance();
		ui.setUIState(uiState);
		if (ctx != null) {
			for (Iterator<String> it = ctx.keySet().iterator(); it.hasNext();) {
				String key = (String) it.next();
				ui.getUiContext().put(key, ctx.get(key));
			}
			ui.setUiContext(ctx);
		}
		ui.onLoad();
		ui.onShow();
		return ui;
	}

	public static CoreUI createUI(String uiClassName) throws Exception {
		return createUI(uiClassName, null, null);
	}
}
